package com.naja.auth2clientfirst.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.jackson2.SecurityJackson2Modules;

/**
 * @auther wangjianying
 * @date 2023/12/12 14:01
 */
@Configuration
public class RedisConfig {
    @Bean
    public RedissonClient getRedisson(RedisProperties redisProperties,ObjectMapper oauth2ObjectMapper) {
        Config config = new Config();
        JsonJacksonCodec jsonJacksonCodec = new JsonJacksonCodec(oauth2ObjectMapper,true);
        config.setCodec(jsonJacksonCodec);
        SingleServerConfig singleServerConfig = config.useSingleServer();
        singleServerConfig.setDatabase(redisProperties.getDatabase());
        singleServerConfig.setAddress("redis://" + redisProperties.getHost() + ":" + redisProperties.getPort());
        RedissonClient redissonClient = Redisson.create(config);
        return redissonClient;
    }

}
